package com.qianfeng.controller;

import com.qianfeng.dto.Page;
import com.qianfeng.entity.Department;
import com.qianfeng.entity.Doctor;
import com.qianfeng.entity.Registration;
import com.qianfeng.service.DepartmentService;
import com.qianfeng.service.DoctorService;
import com.qianfeng.service.RegistrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Controller
public class RegistrationController {
    @Autowired
    private RegistrationService registrationService;
    @Autowired
    private DoctorService doctorService;
    @Autowired
    private DepartmentService departmentService;

    @RequestMapping("/getRegistrationList")
    public String getRegistrationList(){
        return "02_registration_information_management";
    }
    @ResponseBody
    @RequestMapping("/getRegistrationPage")
    public Page getRegistrationPage(Integer pageNo,Integer pageSize){
        int pageNo_=1;
        int pageSize_=2;
        if (pageNo!=null){
            pageNo_=pageNo;
        }
        if (pageSize!=null){
            pageSize_=pageSize;
        }
        Page page = registrationService.getRegistrationPage(pageNo_, pageSize_);
        return page;
    }
    @RequestMapping("/deleteRegistration")
    public String deleteRegistration(Integer rId){
        registrationService.deleteRegistration(rId);
        return "02_registration_information_management";
    }
    @RequestMapping("/jumpAddRegistration")
    public String jumpAddRegistration(Map map){
        List<Doctor> doctorList = doctorService.getDoctorList();
        map.put("doctor",doctorList);
        List<Department> departmentList = departmentService.getDepartmentList();
        map.put("department",departmentList);
        return "02_01_registration_add";
    }

    @RequestMapping("/addRegistration")
    public String addRegistration(Registration registration){
        registration.setrStatus(1);
        registration.setrTime(new Date());
        registrationService.addRegistration(registration);
        return "02_registration_information_management";
    }

    @RequestMapping("/jumpUpdateRegistration")
    public String jumpUpdateRegistration(Integer rId ,Map map){
        Registration registration = registrationService.getRegistrationById(rId);
        map.put("registration",registration);
        List<Department> departmentList = departmentService.getDepartmentList();
        map.put("department",departmentList);
        List<Doctor> doctorList = doctorService.getDoctorList();
        map.put("doctor",doctorList);
        return "02_02_registration_update";
    }
    @RequestMapping("/updateRegistration")
    public String updateRegistration(Registration registration){
        System.out.println(registration);
        registrationService.updateRegistration(registration);
        return "02_registration_information_management";
    }
    @RequestMapping("/getRegistrationDetail")
    public String getRegistrationDetail(Integer rId,Map map){
        Registration registration = registrationService.getRegistrationById(rId);
        map.put("registration",registration);
        List<Department> departmentList = departmentService.getDepartmentList();
        map.put("department",departmentList);
        List<Doctor> doctorList = doctorService.getDoctorList();
        map.put("doctor",doctorList);
        return "02_03_registration_detail";
    }







}
